/*
 * @Date: 2023-01-22 03:27:14
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 05:39:39
 * @FilePath: \campus-repair-platform\server\routes\manage\repair.js
 */
const express = require("express")
// 创建路由对象
const router = express.Router()

const repairService = require("../../service/manage/repair")
// 验证表单中间件
const expressJoi = require('@escook/express-joi')
// 导入需要的验证规则对象
const { list_schema } = require("../../schema/common/repair")
const {
  state_schema,
  examine_schema,
  query_schema
} = require("../../schema/manage/repair")


router.use((req, res, next) => {
  if (req.auth?.type === 3 || req.auth?.type === 4) next() // pass control to the next handler

  else { console.log(1); res.errSend("没有权限访问", 10002) }
})

// 获取报修单列表
router.post("/", expressJoi(list_schema), repairService.listRepair)
// 修改报修单状态
router.patch("/", expressJoi(state_schema), repairService.stateRepair)
// 查询报修单信息
router.post("/query", expressJoi(query_schema), repairService.queryRepair)


// 审核报修单
router.post(
  "/pass",
  expressJoi(examine_schema),
  repairService.examineRepair
)

module.exports = router
